//
//  DKAuthStartAlertView.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/29.
//

#import "DKAuthStartAlertView.h"
@interface DKAuthStartAlertView()
@property (nonatomic, weak)zhPopupController * dk_AuthStartAlertViewPop;
@property (nonatomic,strong)DKAuthStartAlertView *dk_AuthStartAlertView;
@property (nonatomic, copy)void(^SureStartAuthAlertBlock)(void);
@end
@implementation DKAuthStartAlertView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.whiteColor;
        self.layer.cornerRadius = 50;
        self.clipsToBounds = YES;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UILabel *dk_AuthStartHeadLab = [[UILabel alloc] init];
    dk_AuthStartHeadLab.textColor = DK_Hex(@"#333333");
    dk_AuthStartHeadLab.font = DK_FONT_Medium(17);
    dk_AuthStartHeadLab.text = @"Tips:";
    [self addSubview:dk_AuthStartHeadLab];
    [dk_AuthStartHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(24)));
        make.centerX.equalTo(self);
    }];
    UILabel *dk_AuthStartContentLab = [[UILabel alloc] init];
    dk_AuthStartContentLab.textColor = DK_Hex(@"#333333");
    dk_AuthStartContentLab.font = DK_FONT_Regular(14);
    dk_AuthStartContentLab.numberOfLines = 0;
    dk_AuthStartContentLab.text = @"*Take a clear frontal photo of your face.\n*Take the photo in a well-lit environment.\n*Don't cover your face.\n*Hold your phone vertically and firmly.";
    [self addSubview:dk_AuthStartContentLab];
    [dk_AuthStartContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_AuthStartHeadLab.mas_bottom).offset(DK_IsWidthScale(19));
        make.left.equalTo(@(DK_IsWidthScale(10)));
        make.right.equalTo(@(-DK_IsWidthScale(10)));
    }];
    UIButton * dk_AuthStartBtn = [[UIButton alloc] init];
    [dk_AuthStartBtn setTitle:@"Start authentication" forState:UIControlStateNormal];
    [dk_AuthStartBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_AuthStartBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_AuthStartBtn setBackgroundColor:DK_Hex(@"#4566FF")];
    dk_AuthStartBtn.layer.cornerRadius = DK_IsWidthScale(25);
    dk_AuthStartBtn.clipsToBounds = YES;
    [dk_AuthStartBtn addTarget:self action:@selector(startAuth) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_AuthStartBtn];
    [dk_AuthStartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.bottom.equalTo(@(-DK_IsWidthScale(40)));
    }];
    //close
    UIButton * dk_AuthStartCloseBtn = [[UIButton alloc] init];
    [dk_AuthStartCloseBtn setBackgroundImage:DK_GetImage(@"dk_LoginAgreementClose") forState:UIControlStateNormal];
    [dk_AuthStartCloseBtn addTarget:self action:@selector(goCancle) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_AuthStartCloseBtn];
    [dk_AuthStartCloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.height.equalTo(@(DK_IsWidthScale(17)));
        make.width.equalTo(@(DK_IsWidthScale(17)));
    }];
}
- (void)startAuth{
    WeakSelf(self)
    if(self.SureStartAuthAlertBlock){
        if(weakSelf.SureStartAuthAlertBlock){
            weakSelf.SureStartAuthAlertBlock();
            [_dk_AuthStartAlertViewPop dismiss];
        }
    }
}
- (void)goCancle{
    [_dk_AuthStartAlertViewPop dismiss];
}

+ (void)dk_ShowAuthStartAlertView:(UIView *)alertView complete:(void(^)(void))complete{
    DKAuthStartAlertView * dk_AuthStartAlertView = [[DKAuthStartAlertView alloc] init];
    zhPopupController * sureAuthStartCtrl = [[zhPopupController alloc] initWithView:dk_AuthStartAlertView size:CGSizeMake(DK_SCREEN_W - DK_IsWidthScale(60), DK_IsWidthScale(284))];
    dk_AuthStartAlertView.SureStartAuthAlertBlock = complete;
    sureAuthStartCtrl.presentationStyle = zhPopupSlideStyleTransform;
    sureAuthStartCtrl.layoutType = zhPopupLayoutTypeCenter;
    sureAuthStartCtrl.presentationTransformScale = 0.56;
    sureAuthStartCtrl.dismissonTransformScale = 0.56;
    sureAuthStartCtrl.dismissOnMaskTouched = NO;
    dk_AuthStartAlertView.dk_AuthStartAlertViewPop = sureAuthStartCtrl;
    [sureAuthStartCtrl showInView:alertView completion:^{
    }];
}
@end
